<?=$this->headTitle('Профайл');?>
<?=$this->jQuery();?>
<?= $this->jQuery()->addJavaScriptFile($this->baseUrl('js/jquery/js/ajaxupload.3.5.js'));?>
<?=$this->jQuery()->addStyleSheet($this->baseUrl('css/upload.css'));?>


<script type="text/javascript">
$(function(){
var btnUpload=$('#upload');
var status=$('#avatar');
var div=$('div#avatar input[type=image]');
var label=$('div#avatar-label');
var hide = function(){
$('span.errors').remove();
$('#upload-label').css('height','21px'); 
}
$('input#email').css('margin-left','5px');
new AjaxUpload(btnUpload, {
	action: '/users/user-login/upload',
	name: 'uploadfile',
	//cache: false,
	autoSubmit:true,
	responseType: 'json',
	onSubmit: function(file, ext){
	if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext)))
	{
		var p = $('span.errors');
		if(p.length>0){
		p.remove();
		}
		// extension is not allowed
		$('#upload-label').css('height','0'); 
		var er= $('div#avatar').append(div);
		er.append('<span class="errors" style="padding-left:40px">Поддерживаемые форматы JPG, PNG или GIF</span>');
		setTimeout(hide,5000);
		//status.text('Поддерживаемые форматы JPG, PNG или GIF');
		return false;
	}
		var ava=$('#avatar');
		
		$('#avatar').attr({'src':'images/ajax-loader.gif','width':'15','height':'15'});
		
		
		div.css('margin',0,'auto');
		ava.append(div);
		//status.text('Загрузка...');
		
		},
		onComplete: function(file, response)
		{
			//On completion clear the status
			status.text('');
			//Add uploaded file to list
			if(response.status==="success")
			{
			var av = $('dl label.optional');
			//var li = $('dl li');
		
	var ava=$('#avatar');
	div.attr({'src':'images/avatars/'+response.filename,'value':'images/avatars/'+response.filename,'width':100,'height':'100'});
	ava.append(label);
	ava.append(div);
	}
	else if(response.status === 'limitmaxsize' || response.status === 'limitmaxsizephp') 
	{
	$('#avatar').append(label);
	var er = $('div#avatar').append(div);
	$('#upload-label').css('height','0'); 
	setTimeout(hide,5000);
	
	er.append('<span class="errors">Максимальный размер загружаемого файла 500 киллобайтов</span>');
	}

	else{
			$('#avatar').append(label);
			$('div#avatar').append(div);
			}
	}
}); 
});
</script>
<?=$this->profile;?>

